<template>
  <a-card :bordered='false'>
    <div class='card-title'>{{ $route.meta.title }}</div>
    <div class='table-operator'>
      <a-row>
        <a-col :span='6'>
          <a-button v-action:add type='primary' icon='plus' @click='handleAdd'>新增服务内容</a-button>
        </a-col>
        <a-col :span='8' :offset='10'>
          <a-input-search
            style='max-width: 300px; min-width: 150px;float: right;'
            v-model='queryParam.search'
            placeholder='请输入服务名称'
            @search='onSearch'
          />
        </a-col>
      </a-row>
    </div>
    <s-table
      ref='table'
      rowKey='service_id'
      :loading='isLoading'
      :columns='columns'
      :data='loadData'
      :pageSize='15'
      :scroll='{x:1220}'

    >
      <div slot='gth' slot-scope='text, item'>
        <div v-action:xstc>
          销售提成：
          {{ types[item.gth_commission_sales_type].text }}
          {{ item.gth_commission_sales }}
          {{ types[item.gth_commission_sales_type].symbols }}
        </div>
        <div v-action:kjtc>
          会计提成：
          {{ types[item.gth_commission_account_type].text }}
          {{ item.gth_commission_account }}
          {{ types[item.gth_commission_account_type].symbols }}
        </div>
        <div v-action:wqtc>
          外勤提成：
          {{ types[item.gth_commission_outworker_type].text }}
          {{ item.gth_commission_outworker }}
          {{ types[item.gth_commission_outworker_type].symbols }}
        </div>

        <div v-action:cbjg>
          成本价格：
          {{ types[item.gth_cost_type].text }}
          {{ item.gth_cost_value }}
          {{ types[item.gth_cost_type].symbols }}
        </div>
        <div v-action:bzjg>
          标准价格：
          {{ item.gth_standard_price }}元
        </div>
      </div>
      <div slot='xgmnsr' slot-scope='text, item'>
        <div v-action:xstc>
          销售提成：
          {{ types[item.xgmnsr_commission_sales_type].text }}
          {{ item.xgmnsr_commission_sales }}
          {{ types[item.xgmnsr_commission_sales_type].symbols }}
        </div>
        <div v-action:kjtc>
          会计提成：
          {{ types[item.xgmnsr_commission_account_type].text }}
          {{ item.xgmnsr_commission_account }}
          {{ types[item.xgmnsr_commission_account_type].symbols }}
        </div>
        <div v-action:wqtc>
          外勤提成：
          {{ types[item.xgmnsr_commission_outworker_type].text }}
          {{ item.xgmnsr_commission_outworker }}
          {{ types[item.xgmnsr_commission_outworker_type].symbols }}
        </div>
        <div v-action:cbjg>
          成本价格：
          {{ types[item.xgmnsr_cost_type].text }}
          {{ item.xgmnsr_cost_value }}
          {{ types[item.xgmnsr_cost_type].symbols }}
        </div>
        <div v-action:bzjg>
          标准价格：
          {{ item.xgmnsr_standard_price }}元
        </div>
      </div>
      <div slot='ybnsr' slot-scope='text, item'>
        <div v-action:xstc>
          销售提成：
          {{ types[item.ybnsr_commission_sales_type].text }}
          {{ item.ybnsr_commission_sales }}
          {{ types[item.ybnsr_commission_sales_type].symbols }}
        </div>
        <div v-action:kjtc>
          会计提成：
          {{ types[item.ybnsr_commission_account_type].text }}
          {{ item.ybnsr_commission_account }}
          {{ types[item.ybnsr_commission_account_type].symbols }}
        </div>
        <div v-action:wqtc>
          外勤提成：
          {{ types[item.ybnsr_commission_outworker_type].text }}
          {{ item.ybnsr_commission_outworker }}
          {{ types[item.ybnsr_commission_outworker_type].symbols }}
        </div>
        <div v-action:cbjg>
          成本价格：
          {{ types[item.ybnsr_cost_type].text }}
          {{ item.ybnsr_cost_value }}
          {{ types[item.ybnsr_cost_type].symbols }}
        </div>
        <div v-action:bzjg>
          标准价格：
          {{ item.ybnsr_standard_price }}元
        </div>
      </div>
      <div slot='remark' slot-scope='text, item'>
        <span v-if='!item.remark'>-</span>
        <a-tooltip v-else placement='top'>
          <template slot='title'>
            <span v-html='item.remark'></span>
          </template>
          <a>{{ item.remark.length <= 10 ? item.remark : item.remark.substr(0, 10) + '...' }}</a>
        </a-tooltip>
      </div>
      <div class='actions' slot='action' slot-scope='text, item'>
        <a v-action:edit @click='handleEdit(item)'>编辑</a>
        <template v-if='!item.is_super'>
          <a v-action:delete @click='handleDelete(item)'>删除</a>
        </template>
      </div>
    </s-table>
    <AddForm ref='AddForm' @handleSubmit='handleRefresh' />
    <!--    <EditForm ref='EditForm' @handleSubmit='handleRefresh' />-->
  </a-card>
</template>

<script>
import * as Api from '@/api/service'
import { STable } from '@/components'
import AddForm from './modules/AddForm'
// import EditForm from './modules/EditForm'

export default {
  name: 'Index',
  components: {
    STable,
    AddForm
    // EditForm
  },
  data() {
    return {
      // 查询参数
      queryParam: {},
      // 正在加载
      isLoading: false,
      // 表头
      columns: [
        {
          title: 'ID',
          width: 60,
          dataIndex: 'service_id'
        },
        {
          title: '服务名称',
          dataIndex: 'service_name'
        },
        {
          title: '个体户',
          dataIndex: 'gth',
          scopedSlots: { customRender: 'gth' }
        },
        {
          title: '小规模纳税人',
          dataIndex: 'xgmnsr',
          scopedSlots: { customRender: 'xgmnsr' }
        },
        {
          title: '一般纳税人',
          dataIndex: 'ybnsr',
          scopedSlots: { customRender: 'ybnsr' }
        },
        {
          title: '备注说明',
          dataIndex: 'store_id',
          scopedSlots: { customRender: 'remark' }
        },
        {
          title: '添加时间',
          dataIndex: 'create_time'
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '180px',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: param => {
        return Api.list({ ...param, ...this.queryParam })
          .then(response => {
            return response.data.list
          })
      },
      types: [
        { text: '收款金额*', symbols: '%' },
        { text: '固定金额', symbols: '元' },
        { text: '每月提成', symbols: '元' }
      ],
      types2: [
        { text: '(成交价格-成本价格)*', symbols: '%' },
        { text: '固定金额', symbols: '元' },
        { text: '每月提成', symbols: '元' }
      ],
      types3: [
        { text: '收款金额*', symbols: '%' },
        { text: '固定金额', symbols: '元' },
        { text: '选择成本费用', symbols: '元' }
      ]

    }
  },
  created() {
    // 获取角色列表
  },
  methods: {

    // 新增记录
    handleAdd() {
      this.$refs.AddForm.add()
    },

    // 编辑记录
    handleEdit(item) {
      this.$refs.AddForm.edit(item)
    },


    // 删除记录
    handleDelete(item) {
      const app = this
      const modal = this.$confirm({
        title: '您确定要删除该记录吗?',
        content: '删除后不可恢复',
        onOk() {
          return Api.deleted({ apiId: item['service_id'] })
            .then(result => {
              app.$message.success(result.message, 1.5)
              app.handleRefresh()
            })
            .finally(result => modal.destroy())
        }
      })
    },

    /**
     * 刷新列表
     * @param Boolean bool 强制刷新到第一页
     */
    handleRefresh(bool = false) {
      this.$refs.table.refresh(bool)
    },

    // 检索查询
    onSearch() {
      this.handleRefresh(true)
    }

  }
}
</script>
